package semantic.jena;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;

public class JenaDemo {

    public static void main(String[] args) {
//        String sparqlQueryString1 = "PREFIX dbont: <http://dbpedia.org/ontology/> " + "PREFIX dbp: <http://dbpedia.org/property/>"
//                + "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>" + "   SELECT ?musician  ?place" + "   FROM<http://dbpedia.org/resource/Daphne_Oram>" + "   WHERE {  "
//                + "       ?musician dbont:birthPlace ?place ." + "        }";
        
        //TODO Jena TDB & SPARQL endpoint
        String qstring = new StringBuilder()
                .append("PREFIX foaf:  <http://xmlns.com/foaf/0.1/>").append('\n')
                .append("SELECT ?name ?o").append('\n')
                .append("WHERE {").append('\n')
                .append("<http://dbpedia.org/resource/%22The_Take_Over,_the_Breaks_Over%22> foaf:name ?name .").append('\n')
                .append("<http://dbpedia.org/resource/%22The_Take_Over,_the_Breaks_Over%22> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o").append('\n')
//                .append("?person foaf:name ?name .").append('\n')
//                .append("?person ?p ?o").append('\n')
                .append("}").append('\n')
                .append("limit 50")
                .toString();

        Query query = QueryFactory.create(qstring);
        QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);

        ResultSet results = qexec.execSelect();
        ResultSetFormatter.out(System.out, results, query);

        qexec.close();
    }
}
